package com.project.cris.SessionBean;

import java.util.ArrayList;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Query;

import javax.ejb.LocalBean;
import javax.persistence.PersistenceContext;

import com.project.cris.SessionBean.Search_PropForSaleRemote;
import com.project.entity.*;

@Stateless
@LocalBean
public class Search_PropForSaleBean implements Search_PropForSaleRemote {
	
	@PersistenceContext
	EntityManager em;
	@Override
	public ArrayList<PropForSale> getAllPropForSale() throws Exception {
		// TODO Auto-generated method stub
		Query query = em.createNamedQuery("PropForSale.findAllPropForSale");
		@SuppressWarnings("unchecked")
		ArrayList<PropForSale> result = (ArrayList<PropForSale>) query
				.getResultList();
		return result;
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<PropForSale> simpleSearch(String title, String address,String typeSale) {
		Query query=em.createNamedQuery("PropForSale.searchSimple");
		query.setParameter("title", "%"+title+"%");
		query.setParameter("address", "%"+address+"%");
		query.setParameter("type","%"+ typeSale+ "%");
		
		return (ArrayList<PropForSale>) query.getResultList();
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<PropForSale> advanceSearch(double priceMin,
			double priceMax, int bedRoomMin, int bedRoomMax, int bathRoomMin,
			int bathRoomMax,
			String hasInterior, String type) {
		Query query=em.createNamedQuery("PropForSale.searchAdvance");
		query.setParameter("priceMin", priceMin);
		query.setParameter("priceMax", priceMax);
		query.setParameter("bedRoomMin", bedRoomMin);
		query.setParameter("bedRoomMax", bedRoomMax);
		query.setParameter("bathRoomMin", bathRoomMin);
		query.setParameter("bathRoomMax", bathRoomMax);
	 
//		query.setParameter("hasInterior", hasInterior);
	
//	
		return (ArrayList<PropForSale>) query.getResultList();
	}
}
